Converted these images to PNG, saving a handful of bytes per image
[adiumx.git] / Utilities / Log Importers / ichat2adium.pl
blobf9721f9b62d4123d536d7392836dc24674e3d477
1 #!/usr/bin/perl
3 # $Id$
5 # This program imports iChat logs using the program Logorrhea. Get it from
6 # http://spiny.com/logorrhea/
8 # Using Logorrhea, export all of your chats.
10 # Then run this script with "ichat2adium.pl filename" or run from the same
11 # directory as the exported contents.
13 # If you pass the "--usernames" flag, the script will prompt you for the
14 # usernames of the various aliases.
16 # The "--primary-user USERNAME" flag will set the name of the user to your
17 # username.
19 # Records that make no sense will be sent to "adiumLogs/bad".
21 # You should be able to drop the adiumLogs folder into ~/Library/Application
22 # Support/Users/YOU/Logs/.
24 use Time::Local;
25 use warnings;
26 use strict;
28 my $file;
29 my $users = 0;
30 my $primary;
31 my @usernames;
32 my @chatnames;
34 if(@ARGV > 0) {
35 $file = $ARGV[0];
36 } else {
37 $file = "iChat Export.txt";
39 for (my $i = 1; $i < @ARGV; $i++) {
40 if ($ARGV[$i] eq "--usernames") {
41 $users = 1;
43 if($ARGV[$i] eq "--primary-user" ) {
44 $primary = $ARGV[$i + 1];
47 open(FILE, $file) or die qq{Unable to open "$file": $!};
49 $/ = "\r";
51 my @input = <FILE>;
53 my $base_out;
55 if ($primary) {
56 $base_out = "AIM.$primary";
57 } else {
58 $base_out = "AIM.iChatLogs";
61 umask(000);
62 mkdir($base_out, 0777) unless (-d $base_out);
64 my $outfile = "$base_out/bad";
66 close(FILE);
68 for (my $i = 0; $i < @input; $i++) {
69 my ($chatname, $sender, $date, $time, $message);
70 my ($day, $month, $year);
71 my ($hh, $mm, $ss, $modTime);
73 $_ = $input[$i];
75 ($chatname, $sender, $date, $time, $message) =
76 /(.*?)\t(.*?)\t(.*?)\t(.*?)\t.*?\t(.*)\r/s;
78 $_ = $date;
80 if($date) {
81 ($month, $day, $year) = /(\d\d)\/(\d\d)\/(\d\d\d\d)/;
84 if($users && $chatname && $sender) {
85 my $userfound = 0;
86 for(my $j = 0; $j < @chatnames; $j++) {
87 if ($chatnames[$j] eq $chatname) {
88 $userfound = 1;
89 $chatname = $usernames[$j];
92 if($userfound == 0) {
93 push(@chatnames, $chatname);
94 print "Enter username associated with $chatname [$sender]:";
95 $/ = "\n";
96 my $input = <STDIN>;
97 chomp($input);
98 if(length($input) == 0) {
99 push(@usernames, $sender);
100 $chatname = $sender;
101 } else {
102 push(@usernames, $input);
103 $chatname = $input;
108 $chatname =~ s/ //g;
110 if($chatname && $sender && $date && $month && $day && $year && $message) {
111 umask(000);
112 mkdir("$base_out/$chatname", 0777) unless (-d "$base_out/$chatname");
114 $outfile = "$base_out/$chatname/$chatname ($year|$month|$day).adiumLog";
115 open(OUT, ">>$outfile");
116 print OUT "$time $sender: $message\n";
117 } else {
118 $outfile = "$base_out/bad";
119 open(OUT, ">>$outfile");
120 print OUT "$input[$i]";
121 print "Bad record found at line $i. Logged in $base_out/bad.\n";
123 close OUT;
125 ($hh, $mm, $ss) = $time =~ /(\d+):(\d+):(\d+)/;
126 $modTime = timelocal($ss, $mm, $hh, $day, $month - 1, $year);
127 utime time, $modTime, $outfile;